package partThree;

import java.io.Serializable;

/*本类用于序列化测试的物科类*/
public class Student2 implements Serializable {
    //定义学生相关的属性并进行封装
    private String name; //姓名
    private int age; //年龄
    private String addr; //地址
    private char gender;//性别

    //2.1 创建本类的无参构造--注意必须手动提供无参构造，否则会被覆盖
    public Student2() {
        System.out.println("我是Student的无参构造");
    }

    //2.2创建全参构造
    public Student2(String name, int age, String addr, char gender) {
        super();//默认调用父类的无参构造
        this.name = name;
        this.age = age;
        this.addr = addr;
        this.gender = gender;
        System.out.println("我是Student的全参构造");
    }

    //3.属性封装后,需要本类提供公共的属性访问与设置方式get()&set()

    /**
     * 自动创建get()&set(),右键-->Source-->Generate Getters and Setters...
     */
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }
    //如果不想查看对象的地址值，而是想查看类型 属性 属性值
    //可以在子类中添加重写的toString()


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", addr='" + addr + '\'' +
                ", gender=" + gender +
                '}';
    }
}